package com.gxcc3.ygps.system.service.impl;

import com.gxcc3.ygps.common.core.domain.entity.SysCheckDetection;
import com.gxcc3.ygps.common.core.domain.entity.SysCheckDispose;
import com.gxcc3.ygps.common.utils.StringUtils;
import com.gxcc3.ygps.system.mapper.SysCheckDisposeMapper;
import com.gxcc3.ygps.system.service.ISysCheckDisposeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class SysCheckDisposeServiceImpl implements ISysCheckDisposeService {


    @Resource
    SysCheckDisposeMapper disposeMapper;


    /**
     * 查询未处置列表
     * @param detection 参数
     * @return 结果
     */
    @Override
    public List<SysCheckDetection> selectNotDisposeList(SysCheckDetection detection) {
        return disposeMapper.selectNotDisposeList(detection);
    }

    /**
     * 校验附件是否满足
     * @param dispose 参数
     * @return 结果
     */
    @Override
    public boolean checkAttachList(SysCheckDispose dispose) {
        List<String> imageAttachList = dispose.getImageAttachList();
        List<String> videoAttachList = dispose.getVideoAttachList();
        boolean stat = StringUtils.isNotEmpty(imageAttachList) && StringUtils.isNotEmpty(videoAttachList);
        System.out.println(stat);
        return StringUtils.isNotEmpty(imageAttachList) && StringUtils.isNotEmpty(videoAttachList);
    }


    /**
     * 处置
     * @param dispose 参数
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int doDispose(SysCheckDispose dispose) {
        int rows = disposeMapper.doDispose(dispose);
        String detectionId = dispose.getDetectionId();
        if (StringUtils.isNotEmpty(dispose.getImageAttachList())){
            disposeMapper.insertDisposeAttach(detectionId,dispose.getImageAttachList(),2);
        }
        if (StringUtils.isNotEmpty(dispose.getVideoAttachList())){
            disposeMapper.insertDisposeAttach(detectionId,dispose.getVideoAttachList(),1);
        }
        return rows;
    }


    /**
     * 获取已处置列表
     * @param dispose 参数
     * @return 结果
     */
    @Override
    public List<SysCheckDispose> selectDisposedList(SysCheckDispose dispose) {
        return disposeMapper.selectDisposedList(dispose);
    }


    /**
     * 获取已处置详情
     * @param id 参数
     * @return 结果
     */
    @Override
    public SysCheckDispose selectDisposeById(Long id) {
        SysCheckDispose dispose = disposeMapper.selectDisposeById(id);
        dispose.setVideoAttachList(disposeMapper.selectDisposeAttachList(dispose.getDetectionId(),1));
        dispose.setImageAttachList(disposeMapper.selectDisposeAttachList(dispose.getDetectionId(),2));
        return dispose;
    }
}
